<?php
//require('Header_iframe.php');
include('../db_connect.php');

$view_courses=true;
$ulinkID= $_POST['ulinkID'];

$str_length=strlen($_POST['ulinkID']);
if($str_length<7 || $str_length >10 ){
	$view_courses=false;
    echo "Sorry, could not validate ULink ID.";
    return;
}

//make sure this user does exist
$sql="select user_id from fb_users where ulink_id='$ulinkID'";
$result = $db->Execute($sql);
$user_id = $result->fields['user_id'];
if(!$user_id)
{
    $view_courses=false;
    echo "Sorry, we can't find this user.";
    return;
}

//we are validated, search for user courses 
if($view_courses){ 
	$sql="select course_id from fb_reach_student_courses where student_ulink='$ulinkID'";
	$result=$db->Execute($sql);
    $num_rec= $result->RecordCount();
    if($num_rec == 0){
        echo "No records for $ulinkID exist. Sorry.";
        return;
    }
    //we have some record(s)...display in a table
    echo "<table class=\"small\" cellspacing=\"5\">";
    echo "<tr><td><b>Course Deptartment</b></td><td><b>Course Number</b></td><td><b>Course Name</b></td></tr>";
    while(!$result->EOF){
            $curr_id=$result->fields['course_id'];
            $sql2="select course_dept, course_num,course_name from fb_courses where id=$curr_id";
            $result2=$db->Execute($sql2);
            echo "<tr><td>".$result2->fields['course_dept']."</td><td>".$result2->fields['course_num']. "</td><td>".$result2->fields['course_name']. "</td></tr>";
        $result->MoveNext();
    }
    echo "</table>";
}
?>
